/**
 * @author yaoyuan
 * @version 1.0
 * @name zjzcVotingApp.controller:MainCtrl
 * @description 主控制器
 */
'use strict';

angular.module('zjzcVotingApp')
    .controller('mainCtrl', ['$scope', '$rootScope', '$state', '$document','userService',function ($scope, $rootScope, $state, $document, userService) {

        $rootScope.configs = {
            imgService: ""
        };
        // 权限控制：针对特定状态，若未登录，则重定向至登录页
        $scope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
            // 对所有跳转执行权限校验
         /**   if(toState.name!=='login' && !$rootScope.me){
                userService.getUserInfo(function(res) {
                    if (res.flag==='1') {
                        $rootScope.me = {'username':res.msg.userName};
                    }else{
                        // 重定向至登录页
                        $rootScope.waiting = false;
                        event.preventDefault();
                        $state.go('login');
                    }
                });
            }
            if(toState.name === 'login') {
                userService.getUserInfo(function(res) {
                    if (res.flag==='1') {
                        $rootScope.me = {'username':res.msg.userName};
                        $state.go('index');
                    }else{
                        // 重定向至登录页
                        $rootScope.waiting = false;
                        event.preventDefault();
                    }
                });
            }**/
        });
  }]);
